package org.redr.widgetGUI.core;

import org.redr.widgetGUI.settings.WidgetSettings;
import org.redr.widgetGUI.settings.WidgetState;

import com.trolltech.qt.core.Qt;
import com.trolltech.qt.gui.QLayout;
import com.trolltech.qt.gui.QSizePolicy;
import com.trolltech.qt.gui.QWidget;

public class WidgetBox extends LayoutState {
	
	public WidgetBox(QLayout l, WidgetSettings ws){
		super(l, ws);
		_setSettingWidgetBox();
	}
	
	public WidgetBox(WidgetSettings ws){
		super(ws);
		_setSettingWidgetBox();
	}
	
	public WidgetBox(LayoutState parent, WidgetSettings ws){
		super(parent, ws);
		_setSettingWidgetBox();
	}
	
	public QWidget widget(){
		return widgetBox;
	}
	
	public void addWidget(WidgetState ws){
		System.out.println("Adding widget to the layout");
		addWidget(ws.getWidgetBox());
	}
	
	public void addWidget(QWidget w){
		w.setParent(widgetBox);
		widgetBox.layout().addWidget(w);
	}

	private void _setSettingWidgetBox() {
		// TODO Auto-generated method stub
//		String alignment = _getSetting("alignment", "top");
//		widgetBox.layout().setAlignment(new Qt.Alignment(Qt.AlignmentFlag.AlignTop.value()));
//		if (alignment.equals("top")) widgetBox.layout().setAlignment(new Qt.Alignment(Qt.AlignmentFlag.AlignTop.value()));
//		else if (alignment.equals("bottom")) widgetBox.layout().setAlignment(new Qt.Alignment(Qt.AlignmentFlag.AlignBottom.value()));
//		else if (alignment.equals("left")) widgetBox.layout().setAlignment(new Qt.Alignment(Qt.AlignmentFlag.AlignLeft.value()));
//		else if (alignment.equals("right")) widgetBox.layout().setAlignment(new Qt.Alignment(Qt.AlignmentFlag.AlignRight.value()));
//		else widgetBox.layout().setAlignment(new Qt.Alignment(Qt.AlignmentFlag.AlignTop.value()));
		
		Integer spacing = Integer.parseInt(_getSetting("spacing", "1"));
		// widgetBox.setSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Minimum);
		widgetBox.layout().setWidgetSpacing(spacing);
		
	}

	@Override
	public void removeWidget(WidgetState ws) {
		// TODO Auto-generated method stub
		removeWidget(ws.getWidgetBox());
	}

	@Override
	public void removeWidget(QWidget w) {
		// TODO Auto-generated method stub
		widget().layout().removeWidget(w);
	}

}
